#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e5 + 10;
const int B = 300;

int n, a[N], b[N], m, tot, dfn[N], ind[N], tim, R[N], top[N], son[N], siz[N], fa[N], dep[N];
int cur, ans[N], cnt[N];
bool hav[N];
vec G[N];

struct qry {
	int l, r, x, y, bl, L, id;
} q[N];

void dfs(int x, int p) {
	fa[x] = p; siz[x] = 1; dep[x] = dep[p] + 1;
	for(auto y : G[x])
		if(y ^ p) {
			dfs(y, x); siz[x] += siz[y];
			if(siz[y] > siz[son[x]]) son[x] = y;
		}
}

void dfs1(int x, int anc) {
	top[x] = anc; ind[dfn[x] = ++tim] = x;
	if(son[x]) dfs1(son[x], anc);
	for(auto y : G[x]) if(y ^ fa[x] && y ^ son[x]) dfs1(y, y);
	ind[R[x] = ++tim] = x;
}

int lca(int x, int y) {
	while(top[x] != top[y]) {
		if(dep[top[x]] < dep[top[y]]) swap(x, y);
		x = fa[top[x]];
	}
	return dep[x] < dep[y] ? x : y;
}

void update(int x) {
	if(hav[x]) cur -= !--cnt[a[x]];
	else cur += !cnt[a[x]]++;
	hav[x] ^= 1;
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; rep(i, 1, n) a[i] = b[i] = in;
	rep(i, 1, n - 1) {
		int x = in, y = in;
		G[x].eb(y), G[y].eb(x);
	}
	sort(b + 1, b + n + 1); tot = unique(b + 1, b + n + 1) - b - 1;
	rep(i, 1, n) a[i] = lower_bound(b + 1, b + tot + 1, a[i]) - b;
	dfs(1, 0), dfs1(1, 1);
	rep(i, 1, m) {
		q[i].x = in, q[i].y = in; 
		q[i].id = i; if(dfn[q[i].x] > dfn[q[i].y]) swap(q[i].x, q[i].y);
		q[i].L = lca(q[i].x, q[i].y);
		if(q[i].L == q[i].x || q[i].L == q[i].y) {
			q[i].l = dfn[q[i].x], q[i].r = dfn[q[i].y];
			q[i].L = 0;
		} else q[i].l = R[q[i].x], q[i].r = dfn[q[i].y];
		q[i].bl = (q[i].l - 1) / B + 1;
	}
	sort(q + 1, q + m + 1, [&](auto x, auto y) {
		return x.bl ^ y.bl ? x.bl < y.bl : x.bl & 1 ? x.r < y.r : x.r > y.r;
	});
	int l = 1, r = 0;
	rep(i, 1, m) {
		auto x = q[i];
		while(r < x.r) update(ind[++r]);
		while(r > x.r) update(ind[r--]);
		while(l < x.l) update(ind[l++]);
		while(l > x.l) update(ind[--l]);
		if(x.L) update(x.L);
		ans[x.id] = cur;
		//rep(j, 1, n) cerr << hav[j] << " "; cerr << endl;
		//rep(j, 1, n) cerr << a[j] << " "; cerr << endl;
		//cerr << cur << endl;
		if(x.L) update(x.L);
	} rep(i, 1, m) printf("%d\n", ans[i]);
	return 0;
}
